home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-08 | 24.4 KB | 871 lines | [TEXT/CWIE] |
- // Copyright (C) 1999 Eric Roccasecca. All rights reserved.
-
- #define WINDOWLIBCOMPILE
-
- #include "X_Ray_Priv.h"
- #include "Layers.h"
-
- // Internal Prototypes
- OSErr X_RayLib_Init (CFragInitBlockPtr ibp);
- OSErr X_Ray_RememberNewWindow (WindowPtr theWindow, long windowKind, RgnHandle transRgn, RGBColor *clearColor, WindowPtr behind);
- X_Ray_WindowHandle X_Ray_GetWindowRec (WindowPtr theWindow);
- OSErr X_Ray_DisposeWindow (WindowPtr theWindow);
- void X_Ray_PrepWindowForDisposal (WindowPtr theWindow);
- X_Ray_AppRecHandle X_Ray_GetCurrentAppRec (X_Ray_CommRec *commRecAccess);
- void X_Ray_AddWindowAsTSMWindow (X_Ray_WindowHandle newWindow, WindowPtr behind, X_Ray_CommRec *commRecAccess);
- void X_Ray_AddWindowAsAppWindow (X_Ray_WindowHandle newWindow, WindowPtr behind, X_Ray_CommRec *commRecAccess);
-
-
- #define DO_DEBUG
-
- // Internal Intialization routine
- OSErr X_RayLib_Init (CFragInitBlockPtr ibp)
- {
- return noErr;
- }
-
-
-
- //--------------------------------------------
- // TRANSPARENT WINDOW ROUTINES
- //--------------------------------------------
-
- #pragma export on
- void IsXRayLibInstalled (void)
- {
- // DO NOT EVER CALL THIS FUNCTION
- // see X_Ray.h for more info
-
- SysBeep (1); // this is to be annoying so you you pay attention and do not call this function
- }
- #pragma export off
-
-
- #pragma export on
- OSErr InitTransparentWindows (void)
- {
- X_Ray_AppRecHandle curApp;
- X_Ray_CommRec *commRecAccess;
- OSErr err;
-
- err = Gestalt (kX_RayGestalt, (long*)&commRecAccess);
- if (err)
- return kX_RayExtensionNotFoundError;
-
- curApp = X_Ray_GetCurrentAppRec (commRecAccess);
- if (curApp == nil)
- return kX_RayAppNotInitializedCorrectlyError;
-
- return noErr;
- }
- #pragma export off
-
-
- // Makes a new transparent window
- #pragma export on
- WindowPtr NewTransparentWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, RgnHandle transRgn, RGBColor *clearColor, OSErr *windowErr)
- {
- WindowPtr result;
- long windowKind = 0;
-
- windowKind |= kAppWindow;
- if (clearColor)
- windowKind |= kIsClear;
-
- result = NewCWindow (wStorage, boundsRect, title, false, procID, behind, goAwayFlag, refCon);
- if (result)
- {
- *windowErr = X_Ray_RememberNewWindow (result, windowKind, transRgn, clearColor, behind);
- if (visible)
- {
- ShowWindow (result);
- PaintOne (result, ((WindowPeek)result)->strucRgn); // assures frame looks correct when intersecting other trans windows
- }
- }
- else
- *windowErr = memFullErr;
-
- return result;
- }
- #pragma export off
-
-
- // Gets a new transparent window from a resource file
- #pragma export on
- WindowPtr GetNewTransparentWindow (short windowID, void *wStorage, WindowPtr behind, RgnHandle transRgn, RGBColor *clearColor, OSErr *windowErr)
- {
- WindowPtr result;
- long windowKind = 0;
-
- windowKind |= kAppWindow;
- if (clearColor)
- windowKind |= kIsClear;
-
- result = GetNewCWindow (windowID, wStorage, behind);
- if (result)
- *windowErr = X_Ray_RememberNewWindow (result, windowKind, transRgn, clearColor, behind);
- else
- *windowErr = memFullErr;
-
- return result;
- }
- #pragma export off
-
-
- // Makes a new transparent dialog window
- #pragma export on
- DialogPtr NewTransparentDialog (void *dStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl, RgnHandle transRgn, RGBColor *clearColor, OSErr *windowErr)
- {
- DialogPtr result;
- long windowKind = 0;
-
- windowKind |= kAppDialog;
- if (clearColor)
- windowKind |= kIsClear;
-
- result = NewColorDialog (dStorage, boundsRect, title, false, procID, behind, goAwayFlag, refCon, itmLstHndl);
- if (result)
- {
- *windowErr = X_Ray_RememberNewWindow (result, windowKind, transRgn, clearColor, behind);
- if (visible)
- {
- ShowWindow (result);
- PaintOne (result, ((WindowPeek)result)->strucRgn); // assures frame looks correct when intersecting other trans windows
- }
- }
- else
- *windowErr = memFullErr;
-
- return result;
- }
- #pragma export off
-
-
- // Gets a new transparent dialog window from a resource file
- #pragma export on
- DialogPtr GetNewTransparentDialog (short dialogID, void *dStorage, WindowPtr behind, RgnHandle transRgn, RGBColor *clearColor, OSErr *windowErr)
- {
- DialogPtr result;
- long windowKind = 0;
-
- windowKind |= kAppDialog;
- if (clearColor)
- windowKind |= kIsClear;
-
- result = GetNewDialog (dialogID, dStorage, behind);
- if (result)
- *windowErr = X_Ray_RememberNewWindow (result, windowKind, transRgn, clearColor, behind);
- else
- *windowErr = memFullErr;
-
- return result;
- }
- #pragma export off
-
-
- // Makes a new transparent TSM service window
- #pragma export on
- OSErr NewTransparentServiceWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, ComponentInstance ts, WindowPtr *window, RgnHandle transRgn, RGBColor *clearColor)
- {
- OSErr windowErr;
- long windowKind = 0;
-
- windowKind |= kTSMWindow;
- if (clearColor)
- windowKind |= kIsClear;
- if ((long)ts == kCurrentProcess) // if an application owns a TSM window
- windowKind |= kAppWindow;
-
- windowErr = NewServiceWindow (wStorage, boundsRect, title, false, theProc, behind, goAwayFlag, ts, window);
- if (!windowErr)
- {
- windowErr = X_Ray_RememberNewWindow (*window, windowKind, transRgn, clearColor, behind);
- if (visible)
- {
- ShowWindow (*window);
- PaintOne (*window, ((WindowPeek)*window)->strucRgn); // assures frame looks correct when intersecting other trans windows
- }
- }
-
- return windowErr;
- }
- #pragma export off
-
-
- // Makes an existing TSM service window transparent
- #pragma export on
- OSErr MakeServiceWindowTransparent (WindowPtr theWindow, Boolean visible, WindowPtr behind, ComponentInstance ts, RgnHandle transRgn, RGBColor *clearColor)
- {
- OSErr windowErr;
- long windowKind = 0;
-
- windowKind |= kTSMWindow;
- if (clearColor)
- windowKind |= kIsClear;
- if ((long)ts == kCurrentProcess) // if an application owns a TSM window
- windowKind |= kAppWindow;
-
- windowErr = X_Ray_RememberNewWindow (theWindow, windowKind, transRgn, clearColor, behind);
- if (visible)
- {
- ShowWindow (theWindow);
- PaintOne (theWindow, ((WindowPeek)theWindow)->strucRgn); // assures frame looks correct when intersecting other trans windows
- }
-
- return windowErr;
- }
- #pragma export off
-
-
- // Behaves like CloseWindow for transparent windows
- #pragma export on
- void CloseTransparentWindow (WindowPtr theWindow)
- {
- X_Ray_PrepWindowForDisposal (theWindow);
- CloseWindow (theWindow);
- X_Ray_DisposeWindow (theWindow);
- }
- #pragma export off
-
-
- // Behaves like DisposeWindow for transparent windows
- #pragma export on
- void DisposeTransparentWindow (WindowPtr theWindow)
- {
- X_Ray_PrepWindowForDisposal (theWindow);
- DisposeWindow (theWindow);
- X_Ray_DisposeWindow (theWindow);
- }
- #pragma export off
-
-
- // Behaves like CloseServiceWindow for transparent TSM service windows
- #pragma export on
- OSErr CloseTransparentServiceWindow (WindowPtr theWindow)
- {
- OSErr err;
-
- X_Ray_PrepWindowForDisposal (theWindow);
- err = CloseServiceWindow (theWindow);
- err = X_Ray_DisposeWindow (theWindow);
-
- return err;
- }
- #pragma export off
-
-
- // Behaves like CloseDialog for transparent dialog windows
- #pragma export on
- void CloseTransparentDialog (DialogPtr theDialog)
- {
- X_Ray_PrepWindowForDisposal (theDialog);
- CloseDialog (theDialog);
- X_Ray_DisposeWindow (theDialog);
- }
- #pragma export off
-
-
- // Behaves like DisposeDialog for transparent dialog windows
- #pragma export on
- void DisposeTransparentDialog (DialogPtr theDialog)
- {
- X_Ray_PrepWindowForDisposal (theDialog);
- DisposeDialog (theDialog);
- X_Ray_DisposeWindow (theDialog);
- }
- #pragma export off
-
-
- //--------------------------------------------
- // TRANSPARENT WINDOW UTILITY FUNCTIONS
- //--------------------------------------------
-
-
- // returns the content buffer of a transparent window
- #pragma export on
- GWorldPtr GetTransparentWindowContentGWorld (WindowPtr theWindow)
- {
- X_Ray_WindowHandle theTransWindow;
-
- theTransWindow = X_Ray_GetWindowRec (theWindow);
- if (theTransWindow)
- return (*theTransWindow)->contentBuffer;
- else
- return nil;
- }
- #pragma export off
-
-
- // forces update of a transparent window
- // used mainly after content has been updated after using GetTransparentWindowContentBuffer
- // This should not be used in response to update events because this routine will cause another update event to occur
- // ans seriaously affect the performance of yoru software, as well as look really bad.
- // if updateRgn is nil, enire window is updated
- // note, this works by triggering an internal transparent update event
- // and by invalidating the updateRgn passed to the function in theWindow
- // so your own event handler wiil eventually receive an updateEvent
-
- // actually just copies the contentBuffer back into the window and
- // the X-Ray QuickDraw patches magically take care of the rest
- #pragma export on
- void UpdateTransparentWindow (WindowPtr theWindow, RgnHandle updateRgn)
- {
- X_Ray_WindowHandle clrWinRec;
- GrafPtr curPort;
- PixMapHandle contPMap;
-
- clrWinRec = X_Ray_GetWindowRec (theWindow);
- if (clrWinRec == nil)
- return;
-
- GetPort (&curPort);
- SetPort (theWindow);
-
- contPMap = GetGWorldPixMap ((*clrWinRec)->contentBuffer);
- LockPixels (contPMap);
- CopyBits ((BitMap*)*contPMap, &theWindow->portBits, &(*contPMap)->bounds, &theWindow->portRect, srcCopy, updateRgn);
- UnlockPixels (contPMap);
-
- SetPort (curPort);
- }
- #pragma export off
-
-
- // Returns TRUE if window is a transparent window
- #pragma export on
- Boolean IsWindowTransparent (WindowPtr theWindow)
- {
- X_Ray_WindowHandle trnWinRec;
-
- trnWinRec = X_Ray_GetWindowRec (theWindow);
- if (trnWinRec == nil)
- return false;
- else
- return true;
- }
- #pragma export off
-
-
- // sets a windows level of transparency
- #pragma export on
- void SetWindowTransparency (unsigned short transparency, WindowPtr theWindow)
- {
- GDHandle curGDH;
- CGrafPtr curGWorld;
- X_Ray_WindowHandle transWinRec;
- RGBColor transColor;
-
- transWinRec = X_Ray_GetWindowRec (theWindow);
- if (!transWinRec)
- return;
-
- GetGWorld (&curGWorld, &curGDH);
- SetGWorld ((*transWinRec)->maskBuffer, nil);
-
- (*transWinRec)->transparency = transparency;
- transColor.red = transColor.green = transColor.blue = transparency;
- RGBForeColor (&transColor);
-
- LockPixels (GetGWorldPixMap((*transWinRec)->maskBuffer));
- PaintRect (&(*transWinRec)->maskBuffer->portRect);
- UnlockPixels (GetGWorldPixMap((*transWinRec)->maskBuffer));
-
- BackColor (whiteColor);
- ForeColor (blackColor);
-
- SetGWorld (curGWorld, curGDH); // restore graphics environment
-
- UpdateTransparentWindow (theWindow, nil);
- }
- #pragma export off
-
-
- // retrives the transparency of a window
- // will return noErr if window was found to be transparent
- // *transparency is unchanged if it can not be retrieved
- #pragma export on
- OSErr GetWindowTransparency (unsigned short *transparency, WindowPtr theWindow)
- {
- OSErr err = noErr;
- X_Ray_WindowHandle transWinRec;
-
- if (transparency)
- {
- transWinRec = X_Ray_GetWindowRec (theWindow);
- if (!transWinRec)
- return 1;
-
- *transparency = (*transWinRec)->transparency;
- }
- else
- err = paramErr;
-
- return err;
- }
- #pragma export off
-
-
- // <<< PARTIALLY IMPLEMENTED >>>
- // Sets the clear color for a transparent window
- #pragma export on
- void SetTransparentWindowClearColor (WindowPtr theWindow, RGBColor *newClearColor)
- {
- X_Ray_WindowHandle clrWinRec;
-
- clrWinRec = X_Ray_GetWindowRec (theWindow);
- if ((clrWinRec == nil) || (newClearColor == nil))
- return;
-
- (*clrWinRec)->clearColor = *newClearColor;
- (*clrWinRec)->windowKind |= kIsClear;
-
- // ADD
- // force update of this window here
- UpdateTransparentWindow (theWindow, nil);
- }
- #pragma export off
-
-
- // <<< PARTIALLY IMPLEMENTED >>>
- // Removes the clear color for a transparent window
- #pragma export on
- void RemoveTransparentWindowClearColor (WindowPtr theWindow)
- {
- X_Ray_WindowHandle clrWinRec;
-
- clrWinRec = X_Ray_GetWindowRec (theWindow);
- if (clrWinRec == nil)
- return;
-
- (*clrWinRec)->windowKind &= ~kIsClear;
- (*clrWinRec)->clearColor.red = (*clrWinRec)->clearColor.green = (*clrWinRec)->clearColor.blue = 0xFFFF; // white
-
- // ADD
- // force update of this window
- UpdateTransparentWindow (theWindow, nil);
- }
- #pragma export off
-
-
- // <<< PARTIALLY IMPLEMENTED >>>
- // limits area of window that is transparent
- // X_Ray QD patches do not currently recognize this feature although this routine can be called safely
- #pragma export on
- void SetTransparentWindowTransparentRegion (WindowPtr theWindow, RgnHandle transRgn)
- {
- X_Ray_WindowHandle transWinRec;
-
- transWinRec = X_Ray_GetWindowRec (theWindow);
- if ((transWinRec == nil) || (transRgn == nil))
- return;
-
- CopyRgn (transRgn, (*transWinRec)->transparentRgn);
-
- // ADD
- // force update of this window
- UpdateTransparentWindow (theWindow, nil);
- }
- #pragma export off
-
-
- // <<< PARTIALLY IMPLEMENTED >>>
- // removes limiting area of window that is transparent
- // X_Ray QD patches do not currently recognize this feature although this routine can be called safely
- #pragma export on
- void RemoveTransparentWindowTransparentRegion (WindowPtr theWindow)
- {
- X_Ray_WindowHandle transWinRec;
-
- transWinRec = X_Ray_GetWindowRec (theWindow);
- if (transWinRec == nil)
- return;
-
- SetEmptyRgn ((*transWinRec)->transparentRgn);
-
- // ADD
- // force update of this window
- UpdateTransparentWindow (theWindow, nil);
- }
- #pragma export off
-
-
- //--------------------------------------------
- // INTERNAL X_RayLIB ROUTINES
- //--------------------------------------------
-
-
- // Allocates and initializes a new transparent window
- OSErr X_Ray_RememberNewWindow (WindowPtr theWindow, long windowKind, RgnHandle transRgn, RGBColor *clearColor, WindowPtr behind)
- {
- X_Ray_WindowHandle newWindow;
- OSErr err;
- X_Ray_CommRec *commRecAccess;
- THz curZone;
- GDHandle curGDH;
- CGrafPtr curGWorld;
- RGBColor transColor;
-
- err = Gestalt (kX_RayGestalt, (long*)&commRecAccess);
- if (err)
- return kX_RayExtensionNotFoundError;
-
- newWindow = (X_Ray_WindowHandle)NewHandleSysClear (sizeof(X_Ray_Window)); // create new window record in system heap
- if (newWindow)
- {
- curZone = GetZone ();
- SetZone (SystemZone()); // all transparent window memory is allocated in the system heap
-
- HLock ((Handle)newWindow);
-
- (*newWindow)->theWindow = theWindow;
- (*newWindow)->windowKind = windowKind;
- transColor.red = transColor.green = transColor.blue = (*newWindow)->normalTransparency = (*newWindow)->transparency = kTransparencyNormal;
- (*newWindow)->transparentUpdateRgn = NewRgn(); // default is empty region
- (*newWindow)->transparentRgn = NewRgn(); // default is empty region
- if (clearColor)
- (*newWindow)->clearColor = *clearColor;
- else
- (*newWindow)->clearColor.red = (*newWindow)->clearColor.green = (*newWindow)->clearColor.blue = 0xFFFF; // white
-
- // remember how window is owned
- if (windowKind&kAppWindow)
- (*newWindow)->owner = X_Ray_GetCurrentAppRec (commRecAccess);
- else
- (*newWindow)->owner = nil; // nil if window is TSM window and owned by an operating system process
-
- //set the WDEF
- (*newWindow)->origWDEF = ((WindowPeek)theWindow)->windowDefProc;
- ((WindowPeek)theWindow)->windowDefProc = (Handle)commRecAccess->wdefStub;
-
- // make the buffer areas
- err = NewGWorld (&(*newWindow)->underBuffer, 32, &theWindow->portRect, nil, nil, 0);
- if (err)
- DebugNum (err);
- err = NewGWorld (&(*newWindow)->contentBuffer, 32, &theWindow->portRect, nil, nil, 0);
- if (err)
- DebugNum (err);
- err = NewGWorld (&(*newWindow)->mixBuffer, 32, &theWindow->portRect, nil, nil, 0);
- if (err)
- DebugNum (err);
- err = NewGWorld (&(*newWindow)->maskBuffer, 32, &theWindow->portRect, nil, nil, 0);
- if (err)
- DebugNum (err);
- // initialize the buffers
- GetGWorld (&curGWorld, &curGDH);
-
- SetGWorld ((*newWindow)->underBuffer, nil);
- ForeColor (blackColor);
- BackColor (whiteColor);
- LockPixels (GetGWorldPixMap((*newWindow)->underBuffer));
- EraseRect (&(*newWindow)->underBuffer->portRect);
- UnlockPixels (GetGWorldPixMap((*newWindow)->underBuffer));
-
- SetGWorld ((*newWindow)->contentBuffer, nil);
- ForeColor (blackColor);
- BackColor (whiteColor);
- LockPixels (GetGWorldPixMap((*newWindow)->contentBuffer));
- EraseRect (&(*newWindow)->contentBuffer->portRect);
- UnlockPixels (GetGWorldPixMap((*newWindow)->contentBuffer));
-
- SetGWorld ((*newWindow)->mixBuffer, nil);
- ForeColor (blackColor);
- BackColor (whiteColor);
- LockPixels (GetGWorldPixMap((*newWindow)->mixBuffer));
- EraseRect (&(*newWindow)->mixBuffer->portRect);
- UnlockPixels (GetGWorldPixMap((*newWindow)->mixBuffer));
-
- SetGWorld ((*newWindow)->maskBuffer, nil);
- RGBForeColor (&transColor); // setup default transparency
- LockPixels (GetGWorldPixMap((*newWindow)->maskBuffer));
- PaintRect (&(*newWindow)->maskBuffer->portRect);
- UnlockPixels (GetGWorldPixMap((*newWindow)->maskBuffer));
- BackColor (whiteColor);
- ForeColor (blackColor);
-
- SetGWorld (curGWorld, curGDH); // restore graphics environment
-
- if (windowKind&kTSMWindow)
- X_Ray_AddWindowAsTSMWindow (newWindow, behind, commRecAccess);
- else
- X_Ray_AddWindowAsAppWindow (newWindow, behind, commRecAccess);
-
- HUnlock ((Handle)newWindow);
-
- SetZone (curZone);
-
- return noErr;
- }
- else
- return memFullErr;
- }
-
-
- // adds a new transparent window to the transparent TSM window list in correct order
- void X_Ray_AddWindowAsTSMWindow (X_Ray_WindowHandle newWindow, WindowPtr behind, X_Ray_CommRec *commRecAccess)
- {
- X_Ray_WindowHandle curTransWindow = nil;
- WindowPtr curWindow = nil;
-
- GetFrontServiceWindow (&curWindow);
- curTransWindow = commRecAccess->tsmWindowList;
-
- if ((behind == (WindowPtr)-1) || (curTransWindow == nil)) // window is in front of all others OR windowlist is empty
- {
- (*newWindow)->nextWindow = commRecAccess->tsmWindowList;
- if (commRecAccess->tsmWindowList)
- (*(commRecAccess->tsmWindowList))->previousWindow = newWindow;
-
- if (!(*newWindow)->nextWindow) // fix end of list record
- commRecAccess->tsmLastWindow = newWindow;
-
- commRecAccess->tsmWindowList = newWindow;
- }
- else if (behind == nil) // window is behind all others
- {
- while ((*curTransWindow)->nextWindow)
- curTransWindow = (*curTransWindow)->nextWindow;
- (*newWindow)->previousWindow = curTransWindow;
- (*curTransWindow)->nextWindow = newWindow;
- commRecAccess->tsmLastWindow = newWindow;
- }
- else // window is in the middle of the list
- {
- while (curWindow)
- {
- X_Ray_WindowHandle foundWindow;
-
- foundWindow = X_Ray_GetWindowRec (curWindow);
- if (foundWindow)
- curTransWindow = foundWindow; // remember the last transparent window found in front to back order
- if (curWindow == behind)
- {
- (*newWindow)->nextWindow = (*curTransWindow)->nextWindow;
- (*newWindow)->previousWindow = curTransWindow;
- (*curTransWindow)->nextWindow = newWindow;
- if ((*newWindow)->nextWindow)
- (*((*newWindow)->nextWindow))->previousWindow = newWindow;
- if (!(*newWindow)->nextWindow) // fix end of list record
- commRecAccess->tsmLastWindow = newWindow;
- break;
- }
- else
- curWindow = (WindowPtr)((WindowPeek)curWindow)->nextWindow;
- }
- }
- }
-
-
- // adds a new transparent window to current app's transparent window list
- void X_Ray_AddWindowAsAppWindow (X_Ray_WindowHandle newWindow, WindowPtr behind, X_Ray_CommRec *commRecAccess)
- {
- X_Ray_WindowHandle curTransWindow = nil;
- WindowPtr curWindow = nil;
- X_Ray_AppRecHandle curApp;
-
- curApp = X_Ray_GetCurrentAppRec (commRecAccess);
- curWindow = GetFirstLayerWindow ((*curApp)->appGlobalWindow); // get front of window list of current app
- curTransWindow = (*curApp)->windowList; // get transparent window list of current app
-
- if ((behind == (WindowPtr)-1) || (curTransWindow == nil)) // window is in front of all others OR windowlist is empty
- {
- (*newWindow)->nextWindow = (*curApp)->windowList;
- if ((*curApp)->windowList)
- (*((*curApp)->windowList))->previousWindow = newWindow;
- if (!(*newWindow)->nextWindow) // fix end of list record
- (*curApp)->lastWindow = newWindow;
- (*curApp)->windowList = newWindow;
- }
- else if (behind == nil) // window is behind all others
- {
- while ((*curTransWindow)->nextWindow)
- curTransWindow = (*curTransWindow)->nextWindow;
- (*newWindow)->previousWindow = curTransWindow;
- (*curTransWindow)->nextWindow = newWindow;
- (*curApp)->lastWindow = newWindow;
- }
- else // window is in the middle of the list
- {
- while (curWindow)
- {
- X_Ray_WindowHandle foundWindow;
-
- foundWindow = X_Ray_GetWindowRec (curWindow);
- if (foundWindow)
- curTransWindow = foundWindow;
- if (curWindow == behind)
- {
- (*newWindow)->nextWindow = (*curTransWindow)->nextWindow;
- (*newWindow)->previousWindow = curTransWindow;
- (*curTransWindow)->nextWindow = newWindow;
- if ((*newWindow)->nextWindow)
- (*((*newWindow)->nextWindow))->previousWindow = newWindow;
- if (!(*newWindow)->nextWindow) // fix end of list record
- (*curApp)->lastWindow = newWindow;
- break;
- }
- else
- curWindow = (WindowPtr)((WindowPeek)curWindow)->nextWindow;
- }
- }
- }
-
-
- // returns record of current application
- X_Ray_AppRecHandle X_Ray_GetCurrentAppRec (X_Ray_CommRec *commRecAccess)
- {
- ProcessSerialNumber curSerialNum;
- X_Ray_AppRecHandle curApp;
- OSErr err;
- Boolean sameProcess;
-
- err = GetCurrentProcess (&curSerialNum);
- curApp = commRecAccess->appList;
- while (curApp != nil)
- {
- HLock ((Handle)curApp);
- err = SameProcess (&curSerialNum, &(*curApp)->appSerialNum, &sameProcess);
- HUnlock ((Handle)curApp);
-
- if (sameProcess)
- return curApp;
- curApp = (*curApp)->nextApp;
- }
-
- return nil;
- }
-
-
- //retrieves a X_Ray_WindowHandle corresponding to a WindowPtr
- X_Ray_WindowHandle X_Ray_GetWindowRec (WindowPtr theWindow)
- {
- X_Ray_WindowHandle curWindow;
- OSErr err;
- X_Ray_CommRec *commRecAccess;
- Boolean searchExhaustive = false;
- X_Ray_AppRecHandle curApp;
-
- if (theWindow == nil)
- return nil;
-
- err = Gestalt (kX_RayGestalt, (long*)&commRecAccess);
- if (err)
- return nil;
-
- curWindow = commRecAccess->tsmWindowList;
- while (curWindow)
- {
- if ((*curWindow)->theWindow == theWindow)
- return curWindow;
- curWindow = (*curWindow)->nextWindow;
- }
-
- curApp = commRecAccess->appList;
- while (curApp)
- {
- curWindow = (*curApp)->windowList;
- while (curWindow)
- {
- if ((*curWindow)->theWindow == theWindow)
- return curWindow;
- curWindow = (*curWindow)->nextWindow;
- }
- curApp = (*curApp)->nextApp;
- }
-
- return nil;
- }
-
-
- // Disposes of all memory allocated for a transparent window
- OSErr X_Ray_DisposeWindow (WindowPtr theWindow)
- {
- X_Ray_WindowHandle deadWin;
- X_Ray_CommRec *commRecAccess;
- OSErr err;
-
- err = Gestalt (kX_RayGestalt, (long*)&commRecAccess);
- if (err)
- return kX_RayExtensionNotFoundError;
-
- deadWin = X_Ray_GetWindowRec (theWindow);
- if (!deadWin)
- return paramErr;
-
- HLock ((Handle)deadWin);
-
- // fix list head and tail if necessary
- X_Ray_FixOwningListEnds (deadWin);
-
- // remove from window list
- if ((*deadWin)->nextWindow)
- (*((*deadWin)->nextWindow))->previousWindow = (*deadWin)->previousWindow;
- if ((*deadWin)->previousWindow)
- (*((*deadWin)->previousWindow))->nextWindow = (*deadWin)->nextWindow;
-
- // release allocated memory
- DisposeGWorld ((*deadWin)->underBuffer);
- DisposeGWorld ((*deadWin)->contentBuffer);
- DisposeGWorld ((*deadWin)->mixBuffer);
- DisposeGWorld ((*deadWin)->maskBuffer);
- DisposeRgn ((*deadWin)->transparentUpdateRgn);
- DisposeRgn ((*deadWin)->transparentRgn);
-
- HUnlock ((Handle)deadWin);
-
- DisposeHandle ((Handle)deadWin);
- }
-
-
- // fixes the list head and tail for the window if the window is the head or tail of the list
- void X_Ray_FixOwningListEnds (X_Ray_WindowHandle theWindow)
- {
- X_Ray_CommRec *commRecAccess;
- OSErr err;
-
- err = Gestalt (kX_RayGestalt, (long*)&commRecAccess);
- if (err)
- return;
-
- if (((*theWindow)->windowKind)&kTSMWindow)
- {
- if (theWindow == commRecAccess->tsmWindowList)
- commRecAccess->tsmWindowList = (*theWindow)->nextWindow;
- if (theWindow == commRecAccess->tsmLastWindow)
- commRecAccess->tsmLastWindow = (*theWindow)->previousWindow;
- }
- else
- {
- if (theWindow == (*((*theWindow)->owner))->windowList)
- (*((*theWindow)->owner))->windowList = (*theWindow)->nextWindow;
-
- if (theWindow == (*((*theWindow)->owner))->lastWindow)
- (*((*theWindow)->owner))->lastWindow = (*theWindow)->previousWindow;
- }
- }
-
-
- // sets windowKind to kWindowDisposed so other X_Ray QuickDraw routines will ignore window
- void X_Ray_PrepWindowForDisposal (WindowPtr theWindow)
- {
- X_Ray_WindowHandle soonToBeDeadWindow;
-
- soonToBeDeadWindow = X_Ray_GetWindowRec (theWindow);
- if (soonToBeDeadWindow)
- {
- HideWindow (theWindow); // make the window "disappear" since it should no longer be graphically calculated
- (*soonToBeDeadWindow)->windowKind |= kWindowDisposed;
- }
- }
-
-
- #ifdef DO_DEBUG
- // shows a number in the debugger
- void DebugNum (long theNum)
- {
- Str15 theNumStr;
-
- NumToString (theNum, theNumStr);
- DebugStr (theNumStr);
- }
- #endif
-